package com.zfast.forge.wechat.utils;

import java.io.UnsupportedEncodingException;
import java.util.Formatter;

/**
 * @description: 编码工具类
 * @author: cynic
 * @create: 2018-11-21 15:33
 **/
public class EncodeUtil {

    public static String convertWxName(String wxName) {
    	if(wxName==null)wxName="";
        String name = "";
        try {
            name = new String(wxName.getBytes("iso-8859-1"), "UTF-8");
        } catch (
                UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return name;
    }

    public static String encodeWxName(String wxName) {
        String name = "";
        try {
            name = new String(wxName.getBytes("UTF-8"), "iso-8859-1");
        } catch (
                UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return name;
    }

    public static String byteToHex(final byte[] hash) {
        Formatter formatter = new Formatter();
        for (byte b : hash)
        {
            formatter.format("%02x", b);
        }
        String result = formatter.toString();
        formatter.close();
        return result;
    }
}
